package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkGenerateDialog

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import kotlinx.android.synthetic.main.aibk_adapter_item_themetype_rank.view.*

class AibkThemeTypeAdapter(
        val activity: AppCompatActivity,
        val dataList: List<String>,
        var currentThemeName:String
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_themetype_rank, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        var themeName = dataList[position]

        holder.convertView.TvThemeTypeName.text = themeName
        holder.convertView.TvThemeTypeName.isSelected = currentThemeName==themeName
        holder.convertView.TvThemeTypeName.setOnClickListener {
            currentThemeName = themeName
            clickQuesTypeListener!!.onClickThemeType(themeName)
        }

    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    private var clickQuesTypeListener: OnClickQuesTypeListener? = null

    /*
   * 设置点击事件
   * */
    interface OnClickQuesTypeListener {
        fun onClickThemeType(themeName:String)
    }

    fun setClickDialogListener(clickQuesTypeListener: OnClickQuesTypeListener?) {
        this.clickQuesTypeListener = clickQuesTypeListener
    }

}